from time import sleep
import yaml
from selenium import webdriver
from selenium.webdriver.common.by import By


class TestWeChat:
    def setup(self):
        self.driver = webdriver.Chrome()
        #游览器最大化
        self.driver.maximize_window()
        #5秒的隐式等待
        self.driver.implicitly_wait(5)
    def teardown(self):
        self.driver.quit()
    def test_login(self):
        #打开企业微信页面，需要登录
        self.driver.get("https://work.weixin.qq.com/wework_admin/frame")
        #登录的cookie
        cookies = yaml.safe_load(open("Cookie.yaml"))
        for cookie in cookies:
            #去除expiry
            if 'expiry' in cookie.keys():
                cookie.pop("expiry")
            self.driver.add_cookie(cookie)
        #再次打开企业微信界面
        self.driver.get("https://work.weixin.qq.com/wework_admin/frame")
        #查找到退出按钮登录成功
        assert "退出" == self.driver.find_element(By.ID,"logout").text
        sleep(1.5)


